//你选择掷出 num 个色子，请返回所有点数总和的概率。 
//
// 你需要用一个浮点数数组返回答案，其中第 i 个元素代表这 num 个骰子所能掷出的点数集合中第 i 小的那个的概率。 
//
// 
//
// 示例 1： 
//
// 
//输入：num = 3
//输出：[0.00463,0.01389,0.02778,0.04630,0.06944,0.09722,0.11574,0.12500,0.12500,0.
//11574,0.09722,0.06944,0.04630,0.02778,0.01389,0.00463]
// 
//
// 示例 2： 
//
// 
//输入：num = 5
//输出:[0.00013,0.00064,0.00193,0.00450,0.00900,0.01620,0.02636,0.03922,0.05401,0.
//06944,0.08372,0.09452,0.10031,0.10031,0.09452,0.08372,0.06944,0.05401,0.03922,0.
//02636,0.01620,0.00900,0.00450,0.00193,0.00064,0.00013]
// 
//
// 
//
// 提示： 
//
// 
// 1 <= num <= 11 
// 
//
// 
//
// Related Topics 数学 动态规划 概率与统计 👍 599 👎 0


package LeetCode.editor.cn;

import java.util.Arrays;

/**
 * @author ldltd
 * @date 2025-06-02 19:29:11
 * @description LCR 185.统计结果概率
 */
public class NgeTouZiDeDianShuLcof{
	 public static void main(String[] args) {
	 	 //测试代码
	 	 NgeTouZiDeDianShuLcof fun=new NgeTouZiDeDianShuLcof();
	 	 Solution solution = fun.new Solution();

	 }
	 
//力扣代码
//leetcode submit region begin(Prohibit modification and deletion)
class Solution {
		 /*
		 * n个骰子的解f(n)，其中点数和x的概率为f(n,x)
		 * 已知n-1的解f(n-1),加一个骰子，求n个骰子的点数和为x的概率f(n,x)
		 * 当添加骰子的点数为1，前n-1个骰子点数和为x-1，
		 * 可递推出概率和
		 * */
    public double[] statisticsProbability(int num) {
        double [] dp=new double[6];
		//初始化一个骰子，每个点数的概率都是六分之一
		Arrays.fill(dp,1.0/6.0);
		//从两个骰子开始
		for (int i = 2; i <=num; i++) {
			//一共有n~6n的骰子结果，数量为5n+1
			double [] tem=new double[5*i+1];
			for (int j = 0; j < dp.length; j++) {
				for (int k = 0; k < 6; k++) {
					//将前一轮骰子的点数和加上新骰子的点数
					//新骰子的点数为1~6
					tem[j+k]+=dp[j]/6.0;
				}
			}
			dp=tem;
		}
		return dp;
    }
}
//leetcode submit region end(Prohibit modification and deletion)

}
